package com.tanhua.dubbo.server.api;

import com.alibaba.dubbo.config.annotation.Service;
import com.tanhua.dubbo.server.pojo.Sound;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/**
 * @Author:
 * @Description: 实现添加語音
 * @Date: Created in 16:56 2021/1/17
 * @ModifiedBy:
 */
@Service(version = "1.0.0")
public class SoundApiImpl implements SoundApi {
    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public Boolean saveSound(Sound sound) {
        if (sound.getUserId() == null) {
            return false;
        }
        sound.setId(ObjectId.get());//设置主键id
        sound.setCreated(System.currentTimeMillis());//设置创建时间

        this.mongoTemplate.save(sound);
        return true;

    }

    /**
     * 查询语音
     * @param userId
     * @return
     */
    @Override
    public List<Sound> querySoundList(Long userId) {

        Query query = Query.query(Criteria.where("userId").ne(userId));
        return this.mongoTemplate.find(query,Sound.class);
    }
}
